//
//  ThemeButton.m
//  Weibo
//
//  Created by taoshanchang on 15/1/25.
//  Copyright (c) 2015年 taoshanchang. All rights reserved.
//

#import "ThemeButton.h"
#import "ThemeManager.h"

@implementation ThemeButton

-(id)init{
    self = [super init];
    if(self){
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(themeNotification:) name:kThemeDidChangeNotification object:nil];
    }
    return self;
}

-(id)initWithImage:(NSString *)imageName heighlighted:(NSString *)heighlightImageName{
    self = [self init];
    if(self){
        self.imageName = imageName;
        self.heighlightImageName = heighlightImageName;
    }
    return self;
}
-(id)initWithBackgroundImage:(NSString *)backgroundImageName heighlighted:(NSString *)backgroundHeighlightImageName{
    self = [self init];
    if(self){
        self.backgroundImageName = backgroundImageName;
        self.backgroundHeighlightImageName = backgroundHeighlightImageName;
    }
    return self;
}

-(void)dealloc{
    [[NSNotificationCenter defaultCenter] removeObserver:self name:kThemeDidChangeNotification object:nil];
}

-(void)themeNotification:(NSNotification *)notification{
    [self loadThemeImag];
}

-(void)loadThemeImag{
    ThemeManager *manager = [ThemeManager sharedInstance];
    UIImage *image = [manager getThemeImage:_imageName];
    UIImage *heighlightImage = [manager getThemeImage:_heighlightImageName];
    [self setImage:image forState:UIControlStateNormal];
    [self setImage:heighlightImage forState:UIControlStateHighlighted];
    
    UIImage *backImage = [manager getThemeImage:_backgroundImageName];
    UIImage *backHeighlightImage = [manager getThemeImage:_backgroundHeighlightImageName];
    [self setBackgroundImage:backImage forState:UIControlStateNormal];
    [self setBackgroundImage:backHeighlightImage forState:UIControlStateHighlighted];
}

-(void)setImageName:(NSString *)imageName{
    _imageName = imageName;
    [self loadThemeImag];
}

-(void)setHeighlightImageName:(NSString *)heighlightImageName{
    _heighlightImageName = heighlightImageName;
    [self loadThemeImag];
}

-(void)setBackgroundImageName:(NSString *)backgroundImageName{
    _backgroundImageName = backgroundImageName;
    [self loadThemeImag];
}

-(void)setBackgroundHeighlightImageName:(NSString *)backgroundHeighlightImageName{
    _backgroundHeighlightImageName = backgroundHeighlightImageName;
    [self loadThemeImag];
}



@end
